import SocketServer
import string

PORT = 8037

class EchoRequestHandler(SocketServer.StreamRequestHandler):
    def handle(self):
	while self.rfile:
		request = self.rfile.readline(4096)
		request = string.strip(request)

		if request == "": return


		self.wfile.write(request.upper()+"\n")
	        print "connection from", self.client_address, "request", repr(request)

def main():
	SocketServer.TCPServer.allow_reuse_address = True
	server = SocketServer.TCPServer(("", PORT), EchoRequestHandler)
	print "listening on port", PORT
	try:
		server.serve_forever()
	except KeyboardInterrupt:
		pass

if __name__ == "__main__":
	main()
